import React, { useRef } from 'react';
import { Input } from 'antd';

function UseRefDemo() {
  const inputRef = useRef(null);

  const focusTextInput = () => {
    console.log(inputRef.current);

    if (inputRef.current) {
      inputRef.current.focus();
    }
  };
  return (
    <>
      <Input ref={inputRef} type="text"></Input>
      {/* <input type="text" ref={inputRef} /> */}
      <button type="button" onClick={focusTextInput}>
        点击我让input组件获得焦点
      </button>
    </>
  );
}

export default UseRefDemo;
